#include"processbar.h"
#include<stdlib.h>
#include<time.h>

#define FILESIZE 1024*1024*1024 
//模拟下载场景
void download(callback_t cb)//回调函数的形式
{
  srand(time(NULL)^1023);
  int total=FILESIZE;
  while(total){
    usleep(10000);
    int one=rand()%(1024*1024*4);
    total -= one;
    if(total<0){
      total=0;
  }
  int download =FILESIZE-total;
  double rate =(download*1.0/(FILESIZE))*100.0;
  cb(rate);
 // printf("download: %f\n",rate);//进度条刷新   
  }
}


int main(){
 // process();
  download(process_flush);
  return 0;
}
